using System;
using System.Collections.Generic;

namespace Hematology.Data
{
	public partial class SiteUserExtended : IComparable<SiteUserExtended>
	{
		public SiteUser BaseInfo { get; set; }

		public SiteUserExtended()
		{
			BaseInfo = new SiteUser
			{
				AccessRoles = new List<AccessRole>()
			};
		}

		private void FillUserBase()
		{
			if (UserId.HasValue) BaseInfo = SiteUser.Get(UserId.Value);
		}

		public static SiteUserExtended SearchByEmail(string sEmail)
		{
			SiteUser siteUser = SiteUser.SearchByEmail(sEmail);
			if (siteUser != null && siteUser.UserId.HasValue)
			{
				return Get(siteUser.UserId.Value);
			}
			return null;
		}

		public static List<SiteUserExtended> GetAllUsers()
		{
			return Search();
		}

		public static SiteUserExtended SearchByPasswordKey(string sPasswordKey)
		{
			SiteUser siteUser = SiteUser.SearchByPasswordKey(sPasswordKey);
			if (siteUser != null && siteUser.UserId.HasValue)
			{
				return Get(siteUser.UserId.Value);
			}
			return null;
		}

		public int CompareTo(SiteUserExtended other)
		{
			int iNameComparer = LastName.CompareTo(other.LastName);
			if (iNameComparer == 0)
			{
				iNameComparer = FirstName.CompareTo(other.FirstName);
				if (iNameComparer == 0)
				{
					iNameComparer = MiddleName.CompareTo(other.MiddleName);
				}
			}

			return iNameComparer;
		}

	}
}

